package com.demo.mykotlin.widget

import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.Toast
import androidx.constraintlayout.widget.ConstraintLayout
import com.demo.mykotlin.R
import kotlinx.android.synthetic.main.include_title.view.*

/**
 * 自定义标题栏布局
 * @author wen66to88@163.com
 * @date 2020/5/21 - 11:04
 */
class TitleLayout(context: Context, attrs: AttributeSet) : ConstraintLayout(context, attrs) {
    init {
        LayoutInflater.from(context).inflate(R.layout.include_title, this)
        backBtn.setOnClickListener {
            val activity = context as Activity
            activity.finish()
        }
        editBtn.setOnClickListener {
            Toast.makeText(context, "编辑菜单", Toast.LENGTH_LONG).show()
        }
    }

    /**
     * 获得标题
     */
    fun getTitle(): String {
        return titleTv.text.toString()
    }
}